Skip to content

feat: support compile main-thread script to bytecode in external bundle#2459

Merged
upupming merged 4 commits intomainfrom
feat/external-bundle-mts-bytecode
Apr 22, 2026
Merged

feat: support compile main-thread script to bytecode in external bundle#2459
upupming merged 4 commits intomainfrom
feat/external-bundle-mts-bytecode

Conversation

@upupming
Copy link
Copy Markdown
Collaborator

@upupming upupming commented Apr 14, 2026

Summary by CodeRabbit

  • New Features

    • Main-thread scripts in external bundles can be encoded as bytecode.
    • Added option to specify which main-thread chunks are encoded.
  • Tests

    • Updated tests to validate bytecode encoding and the custom-section structure of bundle outputs.
  • Chores

    • Added a changeset and bumped encoding-related tooling versions.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 14, 2026

🦋 Changeset detected

Latest commit: a2b7429

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@lynx-js/lynx-bundle-rslib-config Patch
@lynx-js/react-umd Patch
@lynx-js/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4b5bf329-db5f-427e-902c-be2d12fe4a13

📥 Commits

Reviewing files that changed from the base of the PR and between 6364902 and 98c0fa6.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • packages/rspeedy/lynx-bundle-rslib-config/package.json
  • packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts
  • packages/webpack/template-webpack-plugin/package.json
✅ Files skipped from review due to trivial changes (3)
  • packages/webpack/template-webpack-plugin/package.json
  • packages/rspeedy/lynx-bundle-rslib-config/package.json
  • packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts

📝 Walkthrough

Walkthrough

Collects main-thread entry chunk names during bundler setup, passes them to ExternalBundleWebpackPlugin via a new mainThreadChunks option, marks matching JS assets for JsBytecode encoding and enables useLepusNG; updates API report, tests, and adds a changeset.

Changes

Cohort / File(s) Summary
Changeset & API
.​changeset/flat-bikes-boil.md, packages/rspeedy/lynx-bundle-rslib-config/etc/lynx-bundle-rslib-config.api.md
Add changeset; API report adds optional mainThreadChunks?: string[] on ExternalBundleWebpackPluginOptions.
Bundler wiring
packages/rspeedy/lynx-bundle-rslib-config/src/externalBundleRslibConfig.ts
Merged previous plugins into a single lynx:external-bundle plugin, changed signature to accept { engineVersion }, made api.modifyBundlerChain async, collect main-thread entry names (entryName + '.js') and pass mainThreadChunks to the webpack plugin.
Webpack plugin
packages/rspeedy/lynx-bundle-rslib-config/src/webpack/ExternalBundleWebpackPlugin.ts
Extended ExternalBundleWebpackPluginOptions with mainThreadChunks?: string[]; encode adds customSections attribute 'encoding':'JsBytecode' for matching chunks and sets useLepusNG: true in encoder options.
Tests
packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts
Adjusted assertions to validate shapes/types in decodedResult['custom-sections']; expect __main-thread entries to be encoded (arrays with numeric first element) and retain previous checks for background entries.
Deps
packages/rspeedy/lynx-bundle-rslib-config/package.json, packages/webpack/template-webpack-plugin/package.json
Bumped @lynx-js/tasm from 0.0.33 to 0.0.35 in two packages.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • colinaaa
  • luhc228

Poem

🐰 I nibble at bundles, mark threads with care,
Main ones turn to bytecode, hopping through the air.
Plugins merged, tests checked, small paws on the run,
I tidy chunk names, and then I'm done. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: support compile main-thread script to bytecode in external bundle' directly and clearly summarizes the main objective: adding bytecode compilation support for main-thread scripts in external bundles, which aligns with all key changes across the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/external-bundle-mts-bytecode
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/external-bundle-mts-bytecode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

❌ Patch coverage is 82.66667% with 13 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ndle-rslib-config/src/externalBundleRslibConfig.ts 81.15% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/rspeedy/lynx-bundle-rslib-config/src/webpack/ExternalBundleWebpackPlugin.ts`:
- Around line 138-142: The check in ExternalBundleWebpackPlugin that uses
this.options.mainThreadChunks?.includes(cur.name) compares against the emitted
asset filename (cur.name) which can include hashes/dirs; change it to compare
normalized chunk/section identity: derive a stable name (e.g., use
cur.chunk?.name or extract a basename/normalized section name from cur.name) and
compare that against a normalized version of this.options.mainThreadChunks (map
the configured names through the same normalization). Update the condition to
use the normalizedChunkName (instead of cur.name) so the JsBytecode branch is
chosen by chunk identity, not the raw emitted filename.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4c307d79-ebf4-4bb5-932b-8792c7227ca4

📥 Commits

Reviewing files that changed from the base of the PR and between 7332eb4 and 25f19ff.

📒 Files selected for processing (5)
  • .changeset/flat-bikes-boil.md
  • packages/rspeedy/lynx-bundle-rslib-config/etc/lynx-bundle-rslib-config.api.md
  • packages/rspeedy/lynx-bundle-rslib-config/src/externalBundleRslibConfig.ts
  • packages/rspeedy/lynx-bundle-rslib-config/src/webpack/ExternalBundleWebpackPlugin.ts
  • packages/rspeedy/lynx-bundle-rslib-config/test/external-bundle.test.ts

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 14, 2026

Merging this PR will degrade performance by 19.63%

❌ 2 regressed benchmarks
✅ 79 untouched benchmarks
⏩ 26 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
003-hello-list-destroyBackground 2.8 ms 3.4 ms -19.26%
002-hello-reactLynx-destroyBackground 669.1 µs 832.6 µs -19.63%

Comparing feat/external-bundle-mts-bytecode (a2b7429) with main (e9fe5c5)

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 14, 2026

React Example

#7487 Bundle Size — 224.41KiB (0%).

a2b7429(current) vs 25b09e9 main#7486(baseline)

Bundle metrics  no changes
                 Current
#7487
     Baseline
#7486
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 179 179
No change  Duplicate Modules 69 69
No change  Duplicate Code 44.51% 44.51%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7487
     Baseline
#7486
No change  IMG 145.76KiB 145.76KiB
No change  Other 78.65KiB 78.65KiB

Bundle analysis reportBranch feat/external-bundle-mts-bytecod...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 14, 2026

Web Explorer

#9061 Bundle Size — 898.15KiB (-0.06%).

a2b7429(current) vs 25b09e9 main#9060(baseline)

Bundle metrics  Change 3 changes Regression 1 regression
                 Current
#9061
     Baseline
#9060
Regression  Initial JS 44.47KiB(+0.01%) 44.46KiB
No change  Initial CSS 2.22KiB 2.22KiB
Change  Cache Invalidation 34.63% 0%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 231(+0.43%) 230
No change  Duplicate Modules 11 11
No change  Duplicate Code 27.21% 27.21%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  Change 2 changes Improvement 2 improvements
                 Current
#9061
     Baseline
#9060
Improvement  JS 494.3KiB (-0.03%) 494.47KiB
Improvement  Other 401.63KiB (-0.1%) 402.02KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch feat/external-bundle-mts-bytecod...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 14, 2026

React External

#605 Bundle Size — 674.83KiB (+15.7%).

a2b7429(current) vs 25b09e9 main#604(baseline)

Bundle metrics  Change 1 change
                 Current
#605
     Baseline
#604
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 98.35% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#605
     Baseline
#604
Regression  Other 674.83KiB (+15.7%) 583.28KiB

Bundle analysis reportBranch feat/external-bundle-mts-bytecod...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 14, 2026

React MTF Example

#620 Bundle Size — 195.57KiB (0%).

a2b7429(current) vs 25b09e9 main#619(baseline)

Bundle metrics  no changes
                 Current
#620
     Baseline
#619
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 173 173
No change  Duplicate Modules 66 66
No change  Duplicate Code 44% 44%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#620
     Baseline
#619
No change  IMG 111.23KiB 111.23KiB
No change  Other 84.34KiB 84.34KiB

Bundle analysis reportBranch feat/external-bundle-mts-bytecod...Project dashboard


Generated by RelativeCIDocumentationReport issue

@upupming upupming force-pushed the feat/external-bundle-mts-bytecode branch from 6364902 to 98c0fa6 Compare April 22, 2026 03:31
@upupming upupming merged commit ea5e30e into main Apr 22, 2026
74 of 79 checks passed
@upupming upupming deleted the feat/external-bundle-mts-bytecode branch April 22, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants